package profiterole.waffle;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

import profiterole.api.Waffle;

public class WaffleUtils {
	
	private WaffleUtils() {
		throw new AssertionError("can't be here");
	}
	
	public static Waffle<?> readFromFile(File f) throws Exception {
		Waffle<?> waffle = null;
		FileInputStream fis = null;
		ObjectInputStream in = null;

		fis = new FileInputStream(f);
		in = new ObjectInputStream(fis);
		waffle = (Waffle<?>)in.readObject();
		in.close();
		return waffle;
	}

	public static void writeToFile(Waffle<?> w, File f) throws IOException {
		FileOutputStream fos = null;
		ObjectOutputStream out = null;

		fos = new FileOutputStream(f);
		out = new ObjectOutputStream(fos);
		out.writeObject(w);
		out.close();
	}
}
